package com.tao.controller;

import com.alibaba.fastjson.JSONObject;
import com.tao.pojo.Sku;
import com.tao.pojo.SkuExample;
import com.tao.service.sku.IskuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;



@Controller
@RequestMapping("/sku")
public class SkuController {
    @Autowired
    IskuService skuService;
    @RequestMapping("/show.do")
    public String show(int productId,ModelMap map){
        map.addAttribute("productId", productId);
        return "sku/show";
    }
    @RequestMapping(value = "/get.do",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getSku(Integer productId){
        SkuExample skuExample=new SkuExample();
        skuExample.createCriteria().andProductIdEqualTo(productId);
        List<Sku> skus=skuService.query(skuExample);
        return JSONObject.toJSONString(skus);
    }
    @RequestMapping(value = "/update.do",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String update(Sku sku){
        int i=skuService.update(sku);
        return JSONObject.toJSONString(String.valueOf(i));
    }
}

